<?php
/**
 * Created by PhpStorm.
 * User: td
 * Date: 15/1/6
 * Time: 上午12:13
 */

namespace Home\Model;
use Think\Model;

class UserModel extends Model{

    protected $tableName = 'user';
    protected $pk         = 'user_id';
    protected $_validate = array(
        //验证手机号码
        array('phone', '', '手机已注册！', 1, 'unique', 3),
        array('phone','require','必须填写手机号！','1'),
        array('phone','_checkPhone','手机号码错误',1,'function'),
        //验证手机验证码
        array('verficode','require','必须填写手机验证码','1'),
        array('verficode','_checkVerfiCode','验证码错误',1,'function'),
        //确认密码
        array('passwd','require','必须填写密码！',1),
        array('passwd','confirm_passwd','两次密码输入不同!',1,'confirm'),
        //确认性别
        array('sex','require','请选择性别',1),

    );

    //判断手机号格式正确
    public static function _checkPhone($phone){
        return (preg_match("/^1[34578]{1}\d{9}$/",$phone));
    }
    //判断验证码是否输入正确
    public static function _checkVerfiCode($verficode){
        if($verficode == $_SESSION['verficode']){
            return true;
        }else{
            return false;
        }
    }



} 